package com.lut.teacher.teacherservice.controller;

import java.util.*;

import com.lut.teacher.teacherservice.utils.PageUtils;
import com.lut.teacher.teacherservice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lut.teacher.teacherservice.entity.TeacherPaperEntity;
import com.lut.teacher.teacherservice.service.TeacherPaperService;



/**
 * 
 *
 * @author tongyerui
 * @email tongyerui@gmail.com
 * @date 2021-07-06 11:31:08
 */
@RestController
@RequestMapping("teacherservice/teacherpaper")
public class TeacherPaperController {
    @Autowired
    private TeacherPaperService teacherPaperService;
    @RequestMapping("teacher/list")
    // @RequiresPermissions("teacherservice:teacherpaper:list")
    public R listpaper(@RequestParam Map<String, Object> params){
        PageUtils page = teacherPaperService.queryPaper(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/data/list")
    // @RequiresPermissions("teacherservice:teacherpaper:list")
    public R datalist(@RequestParam Map<String, Object> params){
        List<Map<String, Object>> maps = teacherPaperService.querydata();
        List<String> indexList=new ArrayList<>();
        List<Integer> countList=new ArrayList<>();
        for(int i=0;i<maps.size();i++){

            indexList.add((String) maps.get(i).get("indexes"));
            countList.add(Integer.parseInt(maps.get(i).get("total").toString()));
        }



        return R.ok().put("indexList",indexList).put("countList",countList);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
   // @RequiresPermissions("teacherservice:teacherpaper:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teacherPaperService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{paperId}")
    //@RequiresPermissions("teacherservice:teacherpaper:info")
    public R info(@PathVariable("paperId") String paperId){
		TeacherPaperEntity teacherPaper = teacherPaperService.getById(paperId);


        return R.ok().put("teacherPaper", teacherPaper);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("teacherservice:teacherpaper:save")
    public R save(@RequestBody TeacherPaperEntity teacherPaper){
		teacherPaperService.save(teacherPaper);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("teacherservice:teacherpaper:update")
    public R update(@RequestBody TeacherPaperEntity teacherPaper){
		teacherPaperService.updateById(teacherPaper);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("teacherservice:teacherpaper:delete")
    public R delete(@RequestBody String[] paperIds){
		teacherPaperService.removeByIds(Arrays.asList(paperIds));

        return R.ok();
    }
    @GetMapping("/hello")
    public R hello(){
        List<Map<String, Object>>getlist = teacherPaperService.getlist();

        return R.ok().put("data",getlist);


    }

}
